﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using Assessment.Model;

namespace Assessment.BLL {
	 	//Sys_User
		public partial class Sys_UserBLL
	{
   		     
		private readonly Assessment.DAL.Sys_UserDAL dal=new Assessment.DAL.Sys_UserDAL();
		public Sys_UserBLL()
		{}
		
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int UserId)
		{
			return dal.Exists(UserId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(Assessment.Model.Sys_User model)
		{
						return dal.Add(model);
						
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Assessment.Model.Sys_User model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int UserId)
		{
			
			return dal.Delete(UserId);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string UserIdlist )
		{
			return dal.DeleteList(UserIdlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Assessment.Model.Sys_User GetModel(int UserId)
		{
			
			return dal.GetModel(UserId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Assessment.Model.Sys_User GetModelByCache(int UserId)
		{
			
			string CacheKey = "Sys_UserModel-" + UserId;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(UserId);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Assessment.Model.Sys_User)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Assessment.Model.Sys_User> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Assessment.Model.Sys_User> DataTableToList(DataTable dt)
		{
			List<Assessment.Model.Sys_User> modelList = new List<Assessment.Model.Sys_User>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Assessment.Model.Sys_User model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Assessment.Model.Sys_User();					
													if(dt.Rows[n]["UserId"].ToString()!="")
				{
					model.UserId=int.Parse(dt.Rows[n]["UserId"].ToString());
				}
																																				model.Account= dt.Rows[n]["Account"].ToString();
																																model.UserPwd= dt.Rows[n]["UserPwd"].ToString();
																																model.UserName= dt.Rows[n]["UserName"].ToString();
																												if(dt.Rows[n]["Gender"].ToString()!="")
				{
					model.Gender=int.Parse(dt.Rows[n]["Gender"].ToString());
				}
																																				model.Birthday= dt.Rows[n]["Birthday"].ToString();
																																model.Phone= dt.Rows[n]["Phone"].ToString();
																																model.CertificateNo= dt.Rows[n]["CertificateNo"].ToString();
																																model.Post= dt.Rows[n]["Post"].ToString();
																																model.Department= dt.Rows[n]["Department"].ToString();
																												if(dt.Rows[n]["RoleId"].ToString()!="")
				{
					model.RoleId=int.Parse(dt.Rows[n]["RoleId"].ToString());
				}
																																if(dt.Rows[n]["CreateUserId"].ToString()!="")
				{
					model.CreateUserId=int.Parse(dt.Rows[n]["CreateUserId"].ToString());
				}
																																				model.CreateDate= dt.Rows[n]["CreateDate"].ToString();
																												if(dt.Rows[n]["UpdateUserId"].ToString()!="")
				{
					model.UpdateUserId=int.Parse(dt.Rows[n]["UpdateUserId"].ToString());
				}
																																				model.UpdateDate= dt.Rows[n]["UpdateDate"].ToString();
																												if(dt.Rows[n]["Valid"].ToString()!="")
				{
					model.Valid=int.Parse(dt.Rows[n]["Valid"].ToString());
				}
																										
				
					modelList.Add(model);
				}
			}
			return modelList;
		}


		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}
		
		
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		
		
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
#endregion
   
	}
}